/**
* @class
* Contains the state for a bizproc's action and used by action trigger widgets to coordinate interation
* between the user and a bizproc.
*/
ksg.ui.Action = function(id, action) {
	this.id = id;
	this.availability = ksg.ui.Availability.NotSet;
	this.action = action;
	
	this.allowOpenParams = false;
	this.states = null;
	this.validParams = null;
	this.currentState = null;
}

ksg.ui.Action.prototype = {
	/**
	* Typically called by an action trigger ui widget like an action button, this method will call
	* the method on the bizproc if the action is available to trigger.
	* @param {Object} param An optional value to pass as the parameter for the action trigger event.
	* @returns {Boolean} true if any other Actions being trigger should also be triggered,
	* false if there is some reason to stop processing the other triggers.
	*/
	trigger: function(param) {
		if(this.action)
			return this.action(param);
		return true;
	},
	
	/**
	* A bizproc will set the action state with this method, which can be used by the action trigger ui widgets
	* to change their behavior.  Not all Actions need to have state, but a classic example is the play/pause
	* action.  When the bizproc is "playing" the state is play and the buttons could show an icon 
	* with a "pause" graphic.  When the user triggers the action, the bizproc would "pause" and the state would
	* change.  The buttons would then show a "play" graphic.
	* @param {String} state an id for the state.
	* @returns this
	*/
	setState: function(state) {
		this.currentState = state;
		return this;
	},
	
	/**
	* A bizproc will set the availability on its actions with this method which will drive the visual cues for
	* the action trigger ui elements, such as being disabled or display:none if needed.
	* @param {ksg.ui.Availability} availability The new availability level.
	* @returns this
	*/
	setAvailability: function(availability) {
		this.availability = availability;
		return this;
	},
	
	/**
	* If a bizproc has an action that has states, it will call this method with the currentState and the list of
	* possible states, which an action trigger ui element can use to drive its visual cues.  
	* @see ksg.ui.Action.setState for more info.
	* @param {String} currentState the id of the current state
	* @param {String[]} states array of possible state choices.
	* @returns this
	*/
	setupStates: function(currentState, states) {
		this.currentState = currentState;
		this.states = states;
		return this;
	},
	
	/**
	* An action may want to be trigger with a parameter, and if so, it will setup the parameter options with this method.
	* An example could be an action that took a true/false value, or even a drop down selector of values such as the months of the year,
	* such that when the user picked a month, it would trigger the action with that month as the parameter.
	* @param {Boolean} allowOpenParams If there are no hard set of valid parameters or if there are, but the user can still pass any value
	* then this should be true.  When true, triggering an action will allow any parameter to be passed and triggered.
	* @param {ksg.ui.ActionParameter[]} validParams The array of valid parameters if needed.
	* @returns this
	*/
	setupTriggerParams: function(allowOpenParams, validParams) {
		this.allowOpenParams = allowOpenParams;
		this.validParams = validParams;
		return this;
	}
};
